import { removeUser } from "@/utils/user";

export default {
  namespaced: true,
  state: {
    token: localStorage.getItem("token") || "",
    userInfo: localStorage.getItem("userInfo")
      ? JSON.parse(localStorage.getItem("userInfo"))
      : {},
    role: localStorage.getItem("role") || "",
    btns: localStorage.getItem("btns")
      ? JSON.parse(localStorage.getItem("btns"))
      : [],
  },
  mutations: {
    // 登录成功设置用户信息
    SET_USER(state, { token, userInfo, role, btns }) {
      state.token = token;
      state.userInfo = userInfo;
      state.role = role;
      state.btns = btns;
    },
    // 退出登录清除用户缓存
    CLEAR_USER() {
      removeUser();
    },
  },
};
